/* eslint-disable @typescript-eslint/no-explicit-any */

import printJS from "print-js";
import { table, image, pdf } from "./type";
const tablePrint = (parameter?: any) => {
	let typeObject: any = table;
	let tableDom = document.querySelector(typeObject.printable);
	if (parameter && parameter.className) tableDom = document.querySelector(parameter.className);
	typeObject.printable = tableDom;
	let stylePrint = typeObject.style;
	if (parameter && parameter.style) typeObject.style = stylePrint + parameter.style;
	printJS(typeObject);
};
const pdfPrint = (parameter?: any) => {
	let typeObject = pdf;
	typeObject.printable = parameter.url;
	printJS(typeObject);
};
const imagePrint = (parameter?: any) => {
	let typeObject = image;
	typeObject.printable = parameter.url;
	printJS(typeObject);
};
const Print = (parameter?: any) => {
	if (!parameter || !parameter.type) {
		tablePrint();
		return;
	}
	switch (parameter.type) {
		case "table":
			tablePrint(parameter);
			break;
		case "image":
			imagePrint(parameter);
			break;
		case "pdf":
			pdfPrint(parameter);
			break;
		default:
			tablePrint(parameter);
			break;
	}
};
export default Print;
